package cn.thoughtworks.school.programCenter.controllers;


import cn.thoughtworks.school.programCenter.annotations.Auth;
import cn.thoughtworks.school.programCenter.entities.User;
import cn.thoughtworks.school.programCenter.exceptions.BusinessException;
import cn.thoughtworks.school.programCenter.services.AssignmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "/api")
public class SurveyController {

    @Autowired
    private AssignmentService assignmentService;

    @PostMapping("/surveys/assignments/{assignmentId}/answers")
    public ResponseEntity submitAnswer(@PathVariable Long assignmentId,
                                       @RequestBody List<Map> submitAnswers,
                                       @Auth User current) throws BusinessException {

        assignmentService.submitSurveyAssignmentAnswer(assignmentId, submitAnswers, current.getId());
        return new ResponseEntity(HttpStatus.CREATED);
    }

}
